package com.lightboat.system.domain;

import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.Fastjson2TypeHandler;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.deser.std.DateDeserializers;
import com.fasterxml.jackson.databind.ser.std.DateSerializer;
import com.lightboat.common.annotation.Excel;
import com.lightboat.common.core.domain.BaseEntity;
import com.lightboat.common.core.domain.bo.AfterSaleOrderProductBo;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.SchemaProperty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;

/**
 * 售后对象 crm_after_sale
 * 
 * @author lightboat
 * @date 2025-09-09
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(title = "售后")
@TableName(value = "crm_after_sale", autoResultMap = true)
public class CrmAfterSale extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /** 售后ID */
    @SchemaProperty(name = "售后ID")
    @TableId
    private Long afterSaleId;

    /** 售后ID */
    @SchemaProperty(name = "外部售后ID")
    @Excel(name = "外部售后ID")
    private String externalAfterSaleId;

    /** 售后编号 */
    @SchemaProperty(name = "售后编号")
    @Excel(name = "售后编号")
    private String afterSaleNo;

    /** 订单ID */
    @SchemaProperty(name = "订单ID")
    @Excel(name = "订单ID")
    private Long orderId;

    /** 外部订单ID */
    @SchemaProperty(name = "外部订单ID")
    @Excel(name = "外部订单ID")
    private String externalOrderId;

    /** 店铺ID */
    @SchemaProperty(name = "店铺ID")
    @Excel(name = "店铺ID")
    private Long shopId;

    /** 门店ID */
    @SchemaProperty(name = "门店ID")
    @Excel(name = "门店ID")
    private Long storeId;

    /** 第三方门店编码 */
    @SchemaProperty(name = "第三方门店编码")
    @Excel(name = "第三方门店编码")
    private String tpStoreCode;

    /** 客户ID */
    @SchemaProperty(name = "客户ID")
    @Excel(name = "客户ID")
    private Long customerId;

    /** 售后类别（1系统 2复购） */
    @SchemaProperty(name = "售后类别（1系统 2复购）")
    @Excel(name = "售后类别", readConverterExp = "1=系统,2=复购")
    @NotNull
    private Integer afterSaleType;

    /** 申请时间 */
    @SchemaProperty(name = "申请时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = DateDeserializers.DateDeserializer.class)
    @JsonSerialize(using = DateSerializer.class)
    @Excel(name = "申请时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date applyTime;

    /** 逾期时间 */
    @SchemaProperty(name = "逾期时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = DateDeserializers.DateDeserializer.class)
    @JsonSerialize(using = DateSerializer.class)
    @Excel(name = "逾期时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date expireTime;

    /** 售后描述 */
    @SchemaProperty(name = "售后描述")
    @Excel(name = "售后描述")
    private String description;

    /** 售后原因 */
    @SchemaProperty(name = "售后原因")
    @Excel(name = "售后原因")
    private String reason;

    /** 退款金额（元） */
    @SchemaProperty(name = "退款金额（元）")
    @Excel(name = "退款金额", readConverterExp = "元=")
    private Long refundPriceFen;

    /** 退单类型（1子单 2整单） */
    @SchemaProperty(name = "退单类型（1子单 2整单）")
    @Excel(name = "退单类型", readConverterExp = "1=子单,2=整单")
    private Integer refundType;

    /** 售后类型（1仅客诉 2仅退款 3退货退款） */
    @SchemaProperty(name = "售后类型（1仅客诉 2仅退款 3退货退款）")
    @Excel(name = "售后类型", readConverterExp = "1=仅客诉,2=仅退款,3=退货退款")
    private Integer type;

    /** 售后状态 */
    @SchemaProperty(name = "售后状态")
    @Excel(name = "售后状态")
    private Integer status;

    /** 订单发货状态（1未发货 2已发货） */
    @SchemaProperty(name = "订单发货状态（1未发货 2已发货）")
    @Excel(name = "订单发货状态", readConverterExp = "1=未发货,2=已发货")
    private Integer sendStatus;

    /** 物流公司 */
    @SchemaProperty(name = "物流公司")
    @Excel(name = "物流公司")
    private String returnDeliverName;

    /** 客户寄回物流单号 */
    @SchemaProperty(name = "客户寄回物流单号")
    @Excel(name = "客户寄回物流单号")
    private String returnDeliverNo;

    /** 客户联系方式 */
    @SchemaProperty(name = "客户联系方式")
    @Excel(name = "客户联系方式")
    private String  returnPhone;

    /** 客户寄回时间 */
    @SchemaProperty(name = "客户寄回时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = DateDeserializers.DateDeserializer.class)
    @JsonSerialize(using = DateSerializer.class)
    @Excel(name = "客户寄回时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date returnTime;

    /** 运费（分） */
    @SchemaProperty(name = "运费（分）")
    @Excel(name = "运费", readConverterExp = "分=")
    private Long deliveryPriceFen;

    /** 支付时间 */
    @SchemaProperty(name = "支付时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = DateDeserializers.DateDeserializer.class)
    @JsonSerialize(using = DateSerializer.class)
    @Excel(name = "支付时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date payTime;

    /** 订单状态 */
    @SchemaProperty(name = "订单状态")
    @Excel(name = "订单状态")
    private Integer orderStatus;

    /** 客户上传售后图片 */
    @SchemaProperty(name = "客户上传售后图片")
    @Excel(name = "客户上传售后图片")
    @TableField(typeHandler = Fastjson2TypeHandler.class)
    private List<String> imageList;

    /** 商品信息 */
    @SchemaProperty(name = "商品信息")
    @Excel(name = "商品信息")
    @TableField(typeHandler = Fastjson2TypeHandler.class)
    private List<AfterSaleOrderProductBo> goods;

    /** 售后单物流信息 */
    @SchemaProperty(name = "售后单物流信息")
    @Excel(name = "售后单物流信息")
    @TableField(typeHandler = Fastjson2TypeHandler.class)
    private JSONArray afterSaleDeliverInfo;

    /** 售后单客户信息 */
    @SchemaProperty(name = "售后单客户信息，非表字段")
    @TableField(exist = false)
    private CrmCustomer customer;
}
